#!/usr/bin/env python
#-------------------------------python----------------------gattopo.py--#
#                                                                       #
#                             Gatto e topo                              #
#                                                                       #
#--Daniele Zambelli-----------------------------------------------2002--#

from pyturtle import Turtle 

class Topo(Turtle):

  def __init__(self):
    Turtle.__init__(self)
    self.up()
    self.setpos((90, -90))
    self.down()

  def scappa(self):
    v=1
    x, y = self.getpos()
    if not (-100<x<100 and -100<y<100):
      self.back(v)
      self.left(90)
      self.forward(v)
    self.forward(v)

class Gatto(Turtle):

  def __init__(self, piano):
    Turtle.__init__(self, piano)
    self.setcolor("red")
    self.setwidth(3)
#    self.up()
#    self.goto((190, 190))
#    self.down()

  def insegui(self, chi):
    if self.distance(chi.getpos())<3:
      self.setpos(chi.getpos())
      return 0
    self.lookat(chi.getpos())
    self.forward(1)
    return 1

      
topo=Topo()
gatto=Gatto(topo.getplane())
while gatto.insegui(topo):
  topo.scappa()
